from django.shortcuts import render

from rest_framework.views import APIView
from .sers import *
from mutils import SMSCode
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

class CodeAPIView(APIView):
    def post(self,request):
        ser=CodeSerializer(data=request.data)
        ser.is_valid(raise_exception=True)
        phone=ser.validated_data.get('phone')

        sms=SMSCode()
        code=sms.random_code()
        Code.objects.create(code=code, phone=phone)
        return Response({'验证码':code})

class UserViewSet(ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer



